package fiuba.descuentos;

import java.util.Timer;
import java.util.TimerTask;

import Helpers.ContextHelper;
import Listeners.CustomLocationListener;
import android.app.Activity;
import android.app.PendingIntent.OnFinished;
import android.content.Intent;
import android.location.Location;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.EditText;

public class Configuration extends ActivityBase {
    /** Called when the activity is first created. */
	Timer myTimer = new Timer();
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.configuration);
                               
        bind();
    }
    
    private Runnable updateLocation = new Runnable() {
    	public void run() {
    		                	
        	EditText latitude = (EditText)((Configuration)ContextHelper.getContextInstance()).findViewById(R.id.latitude);
	    	EditText longitude = (EditText)((Configuration)ContextHelper.getContextInstance()).findViewById(R.id.longitude);
	    	
	    	Location loc = CustomLocationListener.getCurrentLocation();
	    	if(loc != null){
		    	latitude.setText(Double.toString(loc.getLatitude()));
		    	longitude.setText(Double.toString(loc.getLongitude()));
	    	}    	    	    	    	          

    	}
    };
           
    private void timerMethod()
	{
		this.runOnUiThread(updateLocation);
	}
    
    public void bind(){    	    	       
    	myTimer.schedule(new TimerTask() {
	    	@Override
	    	public void run() {
	    		timerMethod();
	    	}	    		    
    	}, 0, 5000);
                              	    		   	    		   
    }
    
    @Override
    public void onPause(){
    	super.onPause();
    	myTimer.cancel();    
    }
}